package code3;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/17 10:26
 * 查找小于target的最大值  ----有bug---解决debug
 */
public class BinarySearchLowerDebug {


    public static <E extends Comparable<E>> int lower(E[] data,E target){

        int left = -1;
        int right = data.length-1;

        while (left < right){
            int mid = left + (right - left)/2;

            //debug
            System.out.println(left + " and  " + right);

            if (data[mid].compareTo(target) < 0){
                //去右边找
                left = mid;
            }else{
                right = mid - 1;
            }
        }
        return left;


    }



    public static void main(String[] args) {
        Integer[] arr = {1,1,3,3,5,5};

//        System.out.println(BinarySearchLower.lower(arr,2));
        for (int i = 0; i <= 6 ; i++) {
            int search = BinarySearchLowerDebug.lower(arr, i);
            System.out.print(search + " ");
        }
        System.out.println();
    }
}
